/**
 * 
 */
package cn.com.generaldata.os.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author acer
 * 
 */
public class BeanLoader {
	private static Log log = LogFactory.getLog(BeanLoader.class);
	private static final String log_header = "[Utils][BeanLoader]";
	private static ApplicationContext appContext;

	static {
		init();
	}

	private static void init() {
		if (log.isDebugEnabled()) {
			log.debug(log_header + "[init]initialize...");
		}
		try {
			String[] springConfigFiles = new String[1];
			springConfigFiles[0] = "applicationContext*.xml";
			appContext = new ClassPathXmlApplicationContext(springConfigFiles);
		} catch (Exception ex) {
			log.error(log_header + "[init]Exception: ", ex);
		}
	}

	public static Object loadBean(String beanName) {
		return appContext.getBean(beanName);
	}
}
